﻿using System.ComponentModel.DataAnnotations.Schema;

namespace star_questionnair.Models;

[Table("question")]
public class Question
{
    [Column("id")]
    public int Id { get; set; }
        
    [Column("questionnaire_id")]
    public int QuestionnaireId { get; set; }

    [Column("type")]
    public string Type { get; set; }
        
    [Column("content")]
    public string Content { get; set; }
        
    public int Ordination { get; set; }
        
    [NotMapped]
    public int Template { get; set; }
        
    [NotMapped]
    public ICollection<Option> Options { get; set; }  // 将字段改为属性
        
    // 替换 getQuestionId() 方法
    public int GetQuestionId()
    {
        return Id;
    }

    public string getQuestionType()
    {
        return Type;
    }
    // 重写 Equals 方法来比较两个 Question 对象是否相等
    public override bool Equals(object obj)
    {
        if (obj is Question other)
        {
            return this.Id == other.Id;  // 比较 Id 是否相同
        }
        return false;
    }

    // 重写 GetHashCode 方法，以便在使用 Hash 集合时能正确计算
    public override int GetHashCode()
    {
        return Id.GetHashCode();
    }
}